package com.example.touch;

import android.content.Intent;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;

import com.example.touch.base.BaseActivity;
import com.example.touch.views.MultiTouchView;
import com.example.touch.views.TouchView;

public class MainActivity extends BaseActivity implements View.OnClickListener, View.OnTouchListener {
    public static final String TAG = "Activity";
    private TouchView mTouchView;
    private MultiTouchView mMultiTouchView;

    @Override
    public int getLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    public void init() {
        mTouchView = findViewById(R.id.touch_view);
        mMultiTouchView = findViewById(R.id.multi_touch_view);
        mMultiTouchView.setOnClickListener(this);
        mTouchView.setOnClickListener(this);
        mTouchView.setOnTouchListener(this);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                Log.d(TAG, "======dispatchTouchEvent=======down : (" + ev.getX() + "," + ev.getY() + ")");
                break;
            case MotionEvent.ACTION_MOVE:
                Log.d(TAG, "======dispatchTouchEvent=====move");
                break;
            case MotionEvent.ACTION_UP:
                Log.d(TAG, "=====dispatchTouchEvent======up");
                break;
            case MotionEvent.ACTION_CANCEL:
                Log.d(TAG, "======dispatchTouchEvent=====cancel");
                break;
        }
        return super.dispatchTouchEvent(ev);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                Log.d(TAG, "======onTouchEvent=====down");
                break;
            case MotionEvent.ACTION_MOVE:
                Log.d(TAG, "======onTouchEvent=====move");
                break;
            case MotionEvent.ACTION_UP:
                Log.d(TAG, "=====onTouchEvent======up");
                break;
            case MotionEvent.ACTION_CANCEL:
                Log.d(TAG, "======onTouchEvent=====cancel");
                break;
        }
        return super.onTouchEvent(event);
    }

    @Override
    public void onClick(View v) {
        Log.d("View", "======onClick=====");
        Intent intent = new Intent(MainActivity.this, ListActivity.class);
        startActivity(intent);
    }

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                Log.d("View", "======onTouch onTouchEvent=====down");
                break;
            case MotionEvent.ACTION_MOVE:
                Log.d("View", "======onTouch onTouchEvent=====move");
                break;
            case MotionEvent.ACTION_UP:
                Log.d("View", "=====onTouch onTouchEvent======up");
                break;
            case MotionEvent.ACTION_CANCEL:
                Log.d("View", "======onTouch onTouchEvent=====cancel");
                break;
        }
        return false;
    }
}